﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AdbRegisterUtils
{
    /// <summary>
    /// ProcessStartInfo配置管理器
    /// </summary>
    public static class ProcessStartInfoManager
    {
        static string workingDirectory = $"{AppDomain.CurrentDomain.BaseDirectory}adb";

        /// <summary>
        /// 获取默认工作目录
        /// </summary>
        public static string DefaultWorkingDirectory => workingDirectory;

        /// <summary>
        /// 获取默认的CMD ProcessStartInfo配置
        /// </summary>
        /// <param name="workingDirectory">工作目录</param>
        /// <param name="showWindow">是否显示窗口</param>
        /// <returns>ProcessStartInfo实例</returns>
        public static ProcessStartInfo GetDefaultCmdStartInfo(string workingDirectory = null, bool showWindow = false)
        {
            return new ProcessStartInfo
            {
                FileName = "cmd.exe",
                RedirectStandardInput = true,
                RedirectStandardOutput = true,
                RedirectStandardError = true,
                UseShellExecute = false,
                CreateNoWindow = !showWindow,
                WorkingDirectory = workingDirectory ?? DefaultWorkingDirectory,
                StandardOutputEncoding = Encoding.UTF8,
                StandardErrorEncoding = Encoding.UTF8
            };
        }

        /// <summary>
        /// 获取ADB ProcessStartInfo配置
        /// </summary>
        /// <param name="workingDirectory">工作目录</param>
        /// <param name="showWindow">是否显示窗口</param>
        /// <returns>ProcessStartInfo实例</returns>
        public static ProcessStartInfo GetAdbStartInfo(string workingDirectory = null, bool showWindow = false)
        {
            return new ProcessStartInfo
            {
                FileName = "adb.exe",
                RedirectStandardInput = true,
                RedirectStandardOutput = true,
                RedirectStandardError = true,
                UseShellExecute = false,
                CreateNoWindow = !showWindow,
                WorkingDirectory = workingDirectory ?? DefaultWorkingDirectory,
                StandardOutputEncoding = Encoding.UTF8,
                StandardErrorEncoding = Encoding.UTF8
            };
        }

    }



}
